package leetcode;

import java.util.Deque;
import java.util.LinkedList;

import static leetcode.Mid_2_AddTwoNumbers.createNode;

/**
 * 描述:206. 反转链表
 *
 * @author Madison You
 * @created 2:04
 */
public class Easy_206_ReverseList {
    public static void main(String[] args) {
        int[] arr1 = {2, 4, 9};
        ListNode node1 = createNode(arr1);
        new Easy_206_ReverseList().reverseList(node1);
    }

    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            /*定义一个临时的变量来存储当前节点的后面节点*/
            ListNode next = curr.next;
            /*主要的反转的逻辑，将当前节点的下一个节点指向前面的节点*/
            /*但是产生了个问题，就是prev节点又指向哪*/
            curr.next = prev;
            /*将prev和curr都往前面移动一位，继续迭代*/
            prev = curr;
            curr = next;
        }
        return prev;
    }
}
